package com.zhuiyun.project.cyclingapplet.controller;

import com.zhuiyun.project.cyclingapplet.entity.ActivtyList;
import com.zhuiyun.project.cyclingapplet.entity.Review;
import com.zhuiyun.project.cyclingapplet.service.IActivtyListService;
import com.zhuiyun.project.cyclingapplet.service.IReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author guojingzhi
 * @since 2024-07-12
 */
@RestController
@RequestMapping("/cyclingapplet/activtyList")
public class ActivtyListController {
    @Autowired
    IActivtyListService activtyListService;
    @Autowired
    IReviewService reviewService;


    @RequestMapping("/selectActivtyList")
    public Map<String,Object> selectActivtyList(){
        //查询有几个活动以及活动的详细信息
        List<ActivtyList> list = activtyListService.list();
        //创建List集合
        List<Review> ReviewList = new ArrayList<Review>();
        //利用for循环遍历 根据activityId查询评论条数以及评论分数
        for(int i = 0; i < list.size(); i++){

            Review review = reviewService.selectByactivityId(list.get(i).getActivityId());
            ReviewList.add(review);
        }

        Map<String, Object> map = new HashMap<>();
        map.put("list",list);
        map.put("ReviewList",ReviewList);
        return map;
    }
}
